<template>
  <view class="container">
    <uni-list>
      <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'person-filled' }" title="昵称" :rightText="user?.nickname" />
      <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'phone-filled' }" title="手机号码" :rightText="user?.mobile" />
      <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'email-filled' }" title="邮箱" :rightText="user?.email" />
      <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'auth-filled' }" title="岗位" :rightText="user?.posts?.map(post => post.name).join(',')" />
      <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'staff-filled' }" title="角色" :rightText="user?.roles?.map(role => role.name).join(',')" />
      <uni-list-item showExtraIcon="true" :extraIcon="{ type: 'calendar-filled' }" title="创建日期" :rightText="parseTime(user?.createTime)" />
    </uni-list>
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { getUserProfile } from "@/api/system/user/profile";
import { parseTime } from "@/utils/ruoyi";

interface User {
  nickname?: string;
  mobile?: string;
  email?: string;
  createTime?: string;
  posts?: { name: string }[];
  roles?: { name: string }[];
}

const user = ref<User | null>(null);

const getUser = async () => {
  try {
    user.value = await getUserProfile();
	console.log('user.value',user.value);
  } catch (error) {
    console.error("获取用户信息失败", error);
  }
};

onMounted(() => {
  getUser();
});
</script>

<style lang="scss">

</style>